[LegacyColorValue = true]; 

{ TSM Trend Adjusted Osc : Trend-Adjusted Oscillator
  Copyright 1997-1999, P.J.Kaufman. All rights reserved.
  Corrects sustained periods where the oscillator has high or low values
  by adjusting by the current trend }

	input: OscLen(20), TrendLen(10);
	vars:	osc(0), trend(0), centerpoint(50), TAosc(0), raw(0); 

	if currentbar < OscLen then begin
			osc = centerpoint;
			TAosc = centerpoint;
			end
		else begin
			if high - low <> 0 then raw = (close - low) / (high - low);
			osc = 100*average(raw,OscLen);
			trend = average(osc,TrendLen);
			TAosc = centerpoint - (trend - osc);
			end;
	plot1 (TAosc, "TSMTAosc");
	plot2 (osc,"TSMosc");